<template>
	<view>
		<scroll-view scroll-x class="nav">
			<view class="flex text-center">
				<view
					class="cu-item flex-sub"
					:class="index==TabCur?'active cur':''"
					v-for="(item,index) in menu"
					:key="index"
					@tap="tabSelect"
					:data-id="index">
						{{item}}
				</view>
			</view>
		</scroll-view>
		
		
		<view class="wrapper">
			
			
			<!-- 全部 -->
			<view class="list" v-show="TabCur == 3">
				<view class="order" v-for="i in list0" :key="i.id" @click="gotoDetail(i)">
					<my-shopcard
						v-for="j in i.orders_detail"
						:key="j.id"
						:img="j.full_goods_pic"
						:name="j.goods_name"
						:number="j.quantity"
						:spec="j.goods_attr"
						:money="j.total_price"
						:state="j.pay_status"
					></my-shopcard>
					
					<view class="state">
						<view>订单号：{{i.trade_no}}</view>
						<view>{{i.status_text}}</view>
					</view>
				</view>
			</view>
			
			<!-- 待付款 -->
			<view class="list" v-show="TabCur == 0">
				<view class="order" v-for="i in list1" :key="i.id" @click="gotoDetail(i)">
					<my-shopcard
						v-for="j in i.orders_detail"
						:key="j.id"
						:img="j.full_goods_pic"
						:name="j.goods_name"
						:number="j.quantity"
						:spec="j.goods_attr"
						:money="j.total_price"
						:state="j.pay_status"
					></my-shopcard>
					
					<view class="state">
						<view>订单号：{{i.trade_no}}</view>
						<view>{{i.status_text}}</view>
					</view>
				</view>
			</view>
			
			<!-- 待发货 -->
			<view class="list" v-show="TabCur == 1">
				<view class="order" v-for="i in list2" :key="i.id" @click="gotoDetail(i)">
					<my-shopcard
						v-for="j in i.orders_detail"
						:key="j.id"
						:img="j.full_goods_pic"
						:name="j.goods_name"
						:number="j.quantity"
						:spec="j.goods_attr"
						:money="j.total_price"
						:state="j.pay_status"
					></my-shopcard>
					
					<view class="state">
						<view>订单号：{{i.trade_no}}</view>
						<view>{{i.status_text}}</view>
					</view>
				</view>
			</view>
			
			<!-- 待收货 -->
			<view class="list" v-show="TabCur == 2">
				<view class="order" v-for="i in list3" :key="i.id" @click="gotoDetail(i)">
					<my-shopcard
						v-for="j in i.orders_detail"
						:key="j.id"
						:img="j.full_goods_pic"
						:name="j.goods_name"
						:number="j.quantity"
						:spec="j.goods_attr"
						:money="j.total_price"
						:state="j.pay_status"
					></my-shopcard>
					
					<view class="state">
						<view>订单号：{{i.trade_no}}</view>
						<view>{{i.status_text}}</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				TabCur: 3,
				scrollLeft: 0,
				menu: ['待付款', '待发货', '待收货', '全部'],
				list0: [],
				list1: [],
				list2: [],
				list3: []
			}
		},
		mounted() {
			this.getList(0);
			this.getList(1);
			this.getList(2);
			this.getList(3);
		},
		methods: {
			tabSelect(e) {
				this.TabCur = e.currentTarget.dataset.id;
				this.scrollLeft = (e.currentTarget.dataset.id - 1) * 60
			},
			getList(type) {
				this.$u.get('order/list?type=' + type).then(res => {
					switch(type) {
						case 0:
							this.list0 = res.data.result.orders;
							break;
						case 1:
							this.list1 = res.data.result.orders;
							break;
						case 2:
							this.list2 = res.data.result.orders;
							break;
						case 3:
							this.list3 = res.data.result.orders;
							break;
					}
				})
			},
			goto(path) {
				uni.setStorage({
					key: 'ordertab',
					data: this.TabCur
				})
				uni.navigateTo({
					url: path,
					animationType: 'slide-in-right',
					animationDuration: 300
				})
			},
			gotoDetail(order) {
				if (order.status == 0) {
					this.$goto('/pages/order/order-create?no=' + order.trade_no)
				} else if (order.status == 1 && order.shipping_status == 0) {
					this.$goto('/pages/order/order-deliver?no=' + order.trade_no)
				} else if (order.status == 1 && order.shipping_status == 1) {
					this.$goto('/pages/order/order-delivered?no=' + order.trade_no)
				} else if (order.status == 2) {
					this.$goto('/pages/order/order-received?no=' + order.trade_no)
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
	page {
		background-color: #F5F5F5;
	}
	.nav {
		background: #F5F5F5;
		color: #9399A7;
	}
	.nav .active {
		color: #1f1f1f;
		font-weight: bold;
	}
	
	.tabbar {
		background-color: #434657;
		position: fixed;
		width: 100%;
		z-index: 999;
		bottom: 0;
		margin: 0;
	}
	
	.list {
		margin: 50rpx 0;
		padding: 0 30rpx 50rpx 30rpx;
		
		.order {
			padding-bottom: 20rpx;
			border-radius: 10rpx;
			background-color: #fff;
			margin-top: 30rpx;
			
			.state {
				display: flex;
				justify-content: space-between;
				align-items: center;
				padding: 0 16rpx;
			}
		}
	}
	.list .card {
		padding: 20rpx;
		background-color: #141439;
		border-radius: 10rpx;
		display: flex;
		align-items: center;
		margin-bottom: 30rpx;
	}
</style>
